<?php
require(__META_CONTROLS_GEN__ . '/SchoolStageMetaControlGen.class.php');

/**
 * This is a MetaControl customizable subclass, providing a QForm or QPanel access to event handlers
 * and QControls to perform the Create, Edit, and Delete functionality of the
 * SchoolStage class.  This code-generated class extends from
 * the generated MetaControl class, which contains all the basic elements to help a QPanel or QForm
 * display an HTML form that can manipulate a single SchoolStage object.
 *
 * To take advantage of some (or all) of these control objects, you
 * must create a new QForm or QPanel which instantiates a SchoolStageMetaControl
 * class.
 *
 * This file is intended to be modified.  Subsequent code regenerations will NOT modify
 * or overwrite this file.
 *
 * @package My QCubed Application
 * @subpackage MetaControls
 */
class SchoolStageMetaControl extends SchoolStageMetaControlGen {
    // Initialize fields with default values from database definition
    /*
		public function __construct($objParentObject, SchoolStage $objSchoolStage) {
			parent::__construct($objParentObject,$objSchoolStage);
			if ( !$this->blnEditMode ){
				$this->objSchoolStage->Initialize();
			}
		}
    */
    public static function Create($objParentObject, $OrgId = null, $StageId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
        // Attempt to Load from PK Arguments
        if (strlen($OrgId) && strlen($StageId)) {
            $objSchoolStage = SchoolStage::LoadArrayByStageIdSchoolId($StageId, $OrgId);

            // SchoolStage was found -- return it!
            if (!empty($objSchoolStage))
                return new SchoolStageMetaControl($objParentObject, $objSchoolStage[0]);


            // If EditOnly is specified, throw an exception
        } else if ($intCreateType == QMetaControlCreateType::EditOnly)
            throw new QCallerException('No PK arguments specified');

        // If we are here, then we need to create a new record
        return new SchoolStageMetaControl($objParentObject, new SchoolStage());
    }
        public function SaveSchoolMarketing() {
        try {

            // Update any fields for controls that have been created

            $this->objSchoolMarketing->SchoolId = $_SESSION['Org']->Id;
            //if ($this->lstSeason) $this->objSchoolMarketing->SeasonId = $this->lstSeason->SelectedValue;

            if ($this->blnEditMode) {
                //Updating
                $this->objSchoolMarketing->UpdateBy   = $CurrentUser;
                $this->objSchoolMarketing->UpdateDate = $dttTime;
            }
            else {
                //New
                $this->objSchoolMarketing->CreateBy   = $CurrentUser;
                $this->objSchoolMarketing->CreateDate = $dttTime;
            }



            // Update any fields for controls that have been created


            if ($this->lstSchoolType) $this->objSchoolMarketing->SchoolTypeId = $this->lstSchoolType->SelectedValue;
            if ($this->lstEduSystem) $this->objSchoolMarketing->EduSystemId = $this->lstEduSystem->SelectedValue;
            if ($this->lstSegment) $this->objSchoolMarketing->SegmentId = $this->lstSegment->SelectedValue;
            if ($this->lstSector) $this->objSchoolMarketing->SectorId = $this->lstSector->SelectedValue;
            if ($this->lstOrderType) $this->objSchoolMarketing->OrderTypeId = $this->lstOrderType->SelectedValue;
            if ($this->txtOrderNote) $this->objSchoolMarketing->OrderNote = $this->txtOrderNote->Text;

            // Update any UniqueReverseReferences (if any) for controls that have been created for it

            // Save the SchoolMarketing object
            $this->objSchoolMarketing->Save();

            // Finally, update any ManyToManyReferences (if any)
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }}


    public function SaveSchoolStage() {
        try {
            $dttTime = new QDateTime();
            $dttTime->setDate (date("Y"), date("m"), date("d"));
            $dttTime->setTime (date("H"), date("i"), date("s"));

            $CurrentUser = $_SESSION['User']['Id'];
            //should change user
            $Euser       = $_SESSION['User']['Id'];
            //$this->objSchoolStage->Euser = $Euser;

                $this->objSchoolStage->SchoolId = $_SESSION['Org']->Id;
                $this->objSchoolStage->StageId = $_SESSION['Stage'];
            if ($this->blnEditMode) {
                //Updating
                $this->objSchoolStage->UpdateBy   = $CurrentUser;
                $this->objSchoolStage->UpdateDate = $dttTime;
            }
            else {
                //New
                $this->objSchoolStage->CreateBy   = $CurrentUser;
                $this->objSchoolStage->CreateDate = $dttTime;


            }


            if ($this->txtFees) $this->objSchoolStage->Fees = $this->txtFees->Text;
            if ($this->txtFeesBooks) $this->objSchoolStage->FeesBooks = $this->txtFeesBooks->Text;
            if ($this->txtTotalNumOfStudents) $this->objSchoolStage->TotalNumOfStudents = $this->txtTotalNumOfStudents->Text;
            if ($this->txtNumOfClasses) $this->objSchoolStage->NumOfClasses = $this->txtNumOfClasses->Text;
            if ($this->txtNumOfHours) $this->objSchoolStage->NumOfHours = $this->txtNumOfHours->Text;


            // Update any UniqueReverseReferences (if any) for controls that have been created for it

            // Save the SchoolStage object
            $this->objSchoolStage->Save();

            // Finally, update any ManyToManyReferences (if any)
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
    }



}
?>